<?php
namespace App\Admin\Renderable;
use App\Models\User\WxUserAvatarFrame;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class UserAvatarFrameRender extends LazyRenderable
{
    public function grid(): Grid
    {
        return Grid::make(new WxUserAvatarFrame(), function (Grid $grid) {
            global $__MINI_GLOBAL_TENANT_ID__;
            if($__MINI_GLOBAL_TENANT_ID__ > 0){
                $grid->model()->where('tenant_id', '=', $__MINI_GLOBAL_TENANT_ID__);
            }
            $grid->quickSearch(['id', 'name', 'description'])->placeholder('搜索头像框ID，名字，描述...');
            $grid->model()->orderBy('id', 'desc');

            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('image_url')->image('', 50, 50);
            $grid->column('type')->sortable()->using([0=>'普通', 1=>'会员', 2=>'金币', 3=>'余额'])->label([
                0 => 'primary',
                1 => '#f3bc6e',
                2 => 'rgb(221, 101, 114)',
                3 => 'rgb(1, 192, 170)'
            ]);
            $grid->column('price')->sortable();
//            $grid->column('description');
            $grid->column('quantity')->sortable();
            $grid->column('status')->sortable()->radio([0=>'正常', 1=>'已下架']);
//            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
        });
    }
}
